package Exception;

public class ExceptionDemo1 {
    public static void main(String[] args) {
        try {
            saveAge(-10);
        } catch (MyException e) {
            System.out.println(e.getMessage());
        }

    }

    public static void saveAge(int age) throws MyException {
        if (age < 0 || age > 120) {
            throw new MyException("年龄不合法~~");
        }else {
            System.out.println("年龄保存成功");
            System.out.println("保存年龄:"+age);
        }

    }
}
